<template>
  <div class="navbar-container">
    <nav class="main-nav" ref="mainNavRef">
      <div class="nav-container" ref="navContainerRef">
        <div class="nav-left">
          <NuxtLink href="/" class="logo">
            <Icon name="carbon:chart-bar" class="logo-icon" />
            <span class="logo-text">深度关联</span>
          </NuxtLink>
        </div>
        <div class="nav-center desktop-only">
          <NuxtLink href="/about" class="nav-link" active-class="active">关于</NuxtLink>
          <NuxtLink href="/subscribe" class="nav-link" active-class="active">订阅</NuxtLink>
          <NuxtLink href="/contactus" class="nav-link" active-class="active">联系我们</NuxtLink>
        </div>
        <div class="nav-right desktop-only">
          <button
              class="desktop-filter-btn"
              @click.stop="toggleDesktopFilters"
              v-if="isHomePage"
          >
            <Icon name="material-symbols:filter-list" class="filter-icon-1" />
            <span class="filter-text">筛选</span>
            <span class="filter-badge" v-if="hasActiveFilters">
              {{ getActiveFilterCount }}
            </span>
          </button>
          <button
              class="login-btn"
              v-if="!isLoggedIn"
              @click="openLoginModal"
          >
            登录
          </button>
          <div
              v-else
              class="user-profile"
              @click="toggleUserMenu"
              ref="userProfileRef"
          >
            <NuxtImg
                :src="userInfo.avatar"
                alt="用户头像"
                class="user-avatar"
                loading="lazy"
            />
            <div class="user-menu" :class="{ 'active': userMenuOpen }">
              <div class="user-info">
                <div class="user-name">{{ userInfo.name }}</div>
                <div class="user-email">{{ userInfo.email }}</div>
              </div>
              <NuxtLink href="/usercenter" class="mobile-nav-link" active-class="active">
                <div>
                  <Icon name="material-symbols:person" class="menu-icon" />
                  <span>个人中心</span>
                </div>
              </NuxtLink>
              <NuxtLink href="/usercenter/usersetting" class="mobile-nav-link" active-class="active">
                <div>
                  <Icon name="material-symbols:settings" class="menu-icon" />
                  <span>设置</span>
                </div>
              </NuxtLink>
              <div class="menu-divider"></div>
              <div class="menu-item logout-item" @click="handleLogout">
                <Icon name="material-symbols:logout" class="menu-icon" />
                <span>退出登录</span>
              </div>
            </div>
          </div>
        </div>
        <button
            class="mobile-menu-btn mobile-only"
            @click.stop="toggleMobileNav"
            aria-label="菜单"
        >
          <Icon name="material-symbols:menu" class="menu-icon" v-if="!mobileNavOpen" />
          <Icon name="material-symbols:close" class="menu-icon" v-else />
        </button>
      </div>
      <div
          class="mobile-nav-menu mobile-only"
          :class="{ 'open': mobileNavOpen }"
          @click.stop
      >
        <NuxtLink href="/about" class="mobile-nav-link" @click="toggleMobileNav" active-class="active">关于</NuxtLink>
        <NuxtLink href="/subscribe" class="mobile-nav-link" @click="toggleMobileNav" active-class="active">订阅</NuxtLink>
        <NuxtLink href="/contactus" class="mobile-nav-link" @click="toggleMobileNav" active-class="active">联系我们</NuxtLink>
        <div v-if="!isLoggedIn">
          <NuxtLink href="#" class="mobile-nav-link login-link" @click="handleMobileLogin">登录</NuxtLink>
        </div>
        <div v-else class="mobile-user-section">
          <div class="mobile-user-info">
            <NuxtImg :src="userInfo.avatar" alt="用户头像" class="mobile-avatar"  loading="lazy"/>
            <div class="mobile-user-details">
              <div class="mobile-user-name">{{ userInfo.name }}</div>
              <div class="mobile-user-email">{{ userInfo.email }}</div>
            </div>
          </div>
          <NuxtLink href="/usercenter" class="mobile-nav-link" active-class="active">
            <Icon name="material-symbols:person" class="menu-icon"/>
            个人中心
          </NuxtLink>
          <NuxtLink href="/usercenter/usersetting" class="mobile-nav-link" active-class="active">
            <Icon name="material-symbols:settings" class="menu-icon"/>
            设置
          </NuxtLink>
          <NuxtLink href="#" class="mobile-nav-link logout-link" @click="handleLogout">
            <Icon name="material-symbols:logout" class="menu-icon" />
            退出登录
          </NuxtLink>
        </div>
      </div>
    </nav>

    <div class="filters-container" ref="filtersContainerRef">
      <div
          class="desktop-filters-panel desktop-only"
          :class="{ 'open': desktopFiltersOpen }"
          @click.stop
          ref="desktopFilterPanelRef"
      >
        <div class="desktop-filter-section">
          <h3 class="filter-section-title">
            <Icon name="material-symbols:category" class="section-icon" />
            新闻分类
          </h3>
          <div class="desktop-category-options">
            <div
                class="desktop-option"
                @click="selectCategory('all')"
                :class="{ 'active': activeCategory === 'all' }"
            >
              全部分类
            </div>
            <div
                v-for="category in allCategories"
                :key="category"
                class="desktop-option"
                @click="selectCategory(category)"
                :class="{ 'active': activeCategory === category }"
            >
              {{ category }}
            </div>
          </div>
        </div>
        <div class="desktop-filter-actions">
          <button
              class="reset-filters-btn"
              @click="resetAllFilters"
              :disabled="!hasActiveFilters"
          >
            重置筛选
          </button>
          <button
              class="apply-filters-btn"
              @click="toggleDesktopFilters"
          >
            应用筛选
          </button>
        </div>
      </div>
      <button
          class="mobile-filter-btn mobile-only"
          @click.stop="toggleMobileFilters"
          v-if="isHomePage"
      >
        <Icon name="material-symbols:filter-list" class="filter-icon-2" />
        筛选
        <span class="filter-badge" v-if="hasActiveFilters">
          {{ getActiveFilterCount }}
        </span>
      </button>
      <div
          class="mobile-filters-panel mobile-only"
          :class="{ 'open': mobileFiltersOpen }"
          @click.stop
      >
        <div class="mobile-filter-section">
          <h3 class="filter-section-title">
            <Icon name="material-symbols:category" class="section-icon" />
            新闻分类
          </h3>
          <div class="mobile-category-options">
            <div
                class="mobile-option"
                @click="selectCategory('all')"
                :class="{ 'active': activeCategory === 'all' }"
            >
              全部分类
            </div>
            <div
                v-for="category in allCategories"
                :key="category"
                class="mobile-option"
                @click="selectCategory(category)"
                :class="{ 'active': activeCategory === category }"
            >
              {{ category }}
            </div>
          </div>
        </div>
        <div class="mobile-filter-actions">
          <button
              class="reset-filters-btn"
              @click="resetAllFilters"
              :disabled="!hasActiveFilters"
          >
            重置筛选
          </button>
          <button
              class="apply-filters-btn"
              @click="toggleMobileFilters"
          >
            应用筛选
          </button>
        </div>
      </div>
    </div>

    <div
        class="active-filters-tags"
        v-if="hasActiveFilters && !mobileFiltersOpen && !desktopFiltersOpen"
    >
      <div class="filter-tag" v-if="activeCategory !== 'all'">
        {{ activeCategory }}
        <button @click="selectCategory('all')" class="remove-filter">
          <Icon name="material-symbols:close" class="close-icon" />
        </button>
      </div>
      <div class="filter-tag" v-if="selectedDate">
        {{ formatDate(selectedDate) }}
        <button @click="clearDateFilter" class="remove-filter">
          <Icon name="material-symbols:close" class="close-icon" />
        </button>
      </div>
      <button
          class="clear-all-filters"
          @click="resetAllFilters"
      >
        清除全部
      </button>
    </div>

    <LoginModal
        :visible="loginModalVisible"
        @close="closeLoginModal"
        @success="handleLoginSuccess"
    />
  </div>
</template>

<script setup lang="ts">
import LoginModal from '@/components/LoginModal/LoginModal.vue';

// 定义接口类型
interface User {
  id: string;
  name: string;
  email: string;
  avatar: string;
}

// Props
const props = defineProps<{
  allCategories: string[];
}>();

//获取当前路由
const route = useRoute();
// 计算属性：判断是否为首页
const isHomePage = computed(() => {
  return route.path === '/';
});

// 检测是否为移动设备
const isMobile = ref<boolean>(false);

// 移动端菜单状态
const mobileNavOpen = ref<boolean>(false);
const mobileFiltersOpen = ref<boolean>(false);
// 桌面端筛选面板状态
const desktopFiltersOpen = ref<boolean>(false);

// 日期筛选相关
const selectedDate = ref<string>('');

// 分类筛选
const activeCategory = ref<string>('all');

// 定义ref引用
const filtersContainerRef = ref<HTMLElement | null>(null);
const navContainerRef = ref<HTMLElement | null>(null);
const mainNavRef = ref<HTMLElement | null>(null);
const userProfileRef = ref<HTMLElement | null>(null);
const desktopFilterPanelRef = ref<HTMLElement | null>(null);

// 监听窗口大小变化
const handleResize = () => {
  isMobile.value = window.innerWidth < 768;
  // 窗口大小变化时关闭移动菜单
  if (!isMobile.value) {
    mobileNavOpen.value = false;
    mobileFiltersOpen.value = false;
  }
};

// 点击外部关闭菜单
const closeMenuOnOutsideClick = (e: MouseEvent) => {
  if (mobileFiltersOpen.value && filtersContainerRef.value &&
      !filtersContainerRef.value.contains(e.target as Node)) {
    mobileFiltersOpen.value = false;
  }

  if (mobileNavOpen.value && navContainerRef.value &&
      !navContainerRef.value.contains(e.target as Node)) {
    mobileNavOpen.value = false;
  }

  if (desktopFiltersOpen.value && desktopFilterPanelRef.value &&
      !desktopFilterPanelRef.value.contains(e.target as Node)) {
    desktopFiltersOpen.value = false;
  }

  if (userMenuOpen.value && userProfileRef.value &&
      !userProfileRef.value.contains(e.target as Node)) {
    userMenuOpen.value = false;
  }
};

onMounted(() => {
  handleResize(); // 初始化
  window.addEventListener('resize', handleResize);
  document.addEventListener('click', closeMenuOnOutsideClick);

  // 检查本地存储中的登录状态
  const savedUser = localStorage.getItem('userInfo');
  if (savedUser) {
    try {
      const user = JSON.parse(savedUser);
      userInfo.value = user;
      isLoggedIn.value = true;
    } catch (e) {
      console.error('Failed to parse saved user info', e);
    }
  }
});

onUnmounted(() => {
  window.removeEventListener('resize', handleResize);
  document.removeEventListener('click', closeMenuOnOutsideClick);
});

// 切换移动端筛选面板
const toggleMobileFilters = () => {
  mobileFiltersOpen.value = !mobileFiltersOpen.value;
  // 打开筛选面板时关闭导航菜单
  if (mobileFiltersOpen.value && mobileNavOpen.value) {
    mobileNavOpen.value = false;
  }

  // 触发筛选变化事件
  emit('filter-change', {
    category: activeCategory.value,
    date: selectedDate.value
  });
};

// 切换桌面端筛选面板
const toggleDesktopFilters = () => {
  desktopFiltersOpen.value = !desktopFiltersOpen.value;

  // 触发筛选变化事件
  if (!desktopFiltersOpen.value) {
    emit('filter-change', {
      category: activeCategory.value,
      date: selectedDate.value
    });
  }
};

// 切换移动端导航菜单
const toggleMobileNav = () => {
  mobileNavOpen.value = !mobileNavOpen.value;
  // 打开导航菜单时关闭筛选面板
  if (mobileNavOpen.value && mobileFiltersOpen.value) {
    mobileFiltersOpen.value = false;
  }
};

// 选择分类
const selectCategory = (category: string) => {
  activeCategory.value = category;

  // 触发筛选变化事件
  emit('filter-change', {
    category: activeCategory.value,
    date: selectedDate.value
  });
};

// 清除日期筛选
const clearDateFilter = () => {
  selectedDate.value = '';

  // 触发筛选变化事件
  emit('filter-change', {
    category: activeCategory.value,
    date: selectedDate.value
  });
};

// 重置所有筛选条件
const resetAllFilters = () => {
  activeCategory.value = 'all';
  selectedDate.value = '';

  // 触发筛选变化事件
  emit('filter-change', {
    category: activeCategory.value,
    date: selectedDate.value
  });
};

// 检查是否有活跃的筛选条件
const hasActiveFilters = computed<boolean>(() => {
  return activeCategory.value !== 'all' || !!selectedDate.value;
});

// 获取活跃筛选条件的数量
const getActiveFilterCount = computed<number>(() => {
  let count = 0;
  if (activeCategory.value !== 'all') count++;
  if (selectedDate.value) count++;
  return count;
});

// 最大可选日期为今天
const maxDate = computed<string>(() => {
  return new Date().toISOString().split('T')[0]!;
});

// 登录相关状态
const loginModalVisible = ref<boolean>(false);
const isLoggedIn = ref<boolean>(false);
const userInfo = ref<User>({
  id: '',
  name: '',
  email: '',
  avatar: ''
});
const userMenuOpen = ref<boolean>(false);

// 打开登录弹窗
const openLoginModal = () => {
  loginModalVisible.value = true;
};

// 关闭登录弹窗
const closeLoginModal = () => {
  loginModalVisible.value = false;
};

// 处理登录成功
const handleLoginSuccess = (user: User) => {
  isLoggedIn.value = true;
  userInfo.value = user;
  loginModalVisible.value = false;

  // 保存用户信息到本地存储
  localStorage.setItem('userInfo', JSON.stringify(user));

  // 关闭移动端菜单（如果打开）
  if (mobileNavOpen.value) {
    mobileNavOpen.value = false;
  }

  // 触发登录成功事件
  emit('login-success', user);
};

// 切换用户菜单
const toggleUserMenu = () => {
  userMenuOpen.value = !userMenuOpen.value;
};

// 处理退出登录
const handleLogout = () => {
  isLoggedIn.value = false;
  userInfo.value = {
    id: '',
    name: '',
    email: '',
    avatar: ''
  };
  userMenuOpen.value = false;

  // 清除本地存储中的用户信息
  localStorage.removeItem('userInfo');

  // 关闭移动端菜单（如果打开）
  if (mobileNavOpen.value) {
    mobileNavOpen.value = false;
  }

  // 触发退出登录事件
  emit('logout');
};

// 处理移动端登录
const handleMobileLogin = () => {
  mobileNavOpen.value = false;
  setTimeout(() => {
    openLoginModal();
  }, 300); // 延迟打开，等待菜单关闭动画完成
};

// 格式化日期显示
const formatDate = (dateString: string): string => {
  const date = new Date(dateString);
  return date.toLocaleDateString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric' });
};

// 定义 emits
const emit = defineEmits<{
  (e: 'filter-change', filters: { category: string; date: string }): void;
  (e: 'login-success', user: User): void;
  (e: 'logout'): void;
}>();
</script>

<style scoped>
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.mobile-only {
  display: none !important;
}

.navbar-container {
  width: 100%;
  margin-bottom: 20px;
}

.filters-container {
  margin-bottom: 20px;
  position: relative;
}

.desktop-filter-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background-color: white;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-right: 15px;
}

.desktop-filter-btn:hover {
  background-color: #f8fcff;
  border-color: #3498db;
  color: #3498db;
}

.desktop-filters-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 350px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  z-index: 100;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: all 0.3s ease;
  margin-top: 5px;
}

.desktop-filters-panel.open {
  max-height: 500px;
  opacity: 1;
  padding-bottom: 15px;
}

.desktop-filter-section {
  padding: 15px;
  border-bottom: 1px solid #f0f0f0;
}

.desktop-filter-section:last-child {
  border-bottom: none;
}

.desktop-category-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.desktop-option {
  padding: 8px 15px;
  text-align: center;
  background-color: #f5f5f5;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.desktop-option:hover {
  background-color: #ebf5fb;
  color: #3498db;
  transform: translateY(-2px);
}

.desktop-option.active {
  background-color: #3498db;
  color: white;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.desktop-date-filter {
  display: flex;
  gap: 10px;
  width: 100%;
}

.desktop-filter-actions {
  display: flex;
  gap: 10px;
  padding: 15px;
}

.mobile-filter-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 15px;
  background-color: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin-bottom: 10px;
}

.mobile-filter-btn:hover {
  background-color: #f8fcff;
  border-color: #3498db;
  color: #3498db;
}

.filter-icon-2 {
  font-size: 1.1rem;
  position: relative;
  top: 3px;
}

.filter-badge {
  background-color: #e74c3c;
  color: white;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.8rem;
  font-weight: 500;
  margin-left: 5px;
}

.mobile-filters-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  z-index: 100;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: all 0.3s ease;
  margin-top: 5px;
}

.mobile-filters-panel.open {
  max-height: 500px;
  opacity: 1;
  padding-bottom: 15px;
}

.mobile-filter-section {
  padding: 15px;
  border-bottom: 1px solid #f0f0f0;
}

.mobile-filter-section:last-child {
  border-bottom: none;
}

.filter-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  color: #2c3e50;
  margin: 0 0 12px 0;
  font-weight: 600;
}

.section-icon {
  color: #3498db;
}

.mobile-category-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mobile-option {
  padding: 10px 5px;
  text-align: center;
  background-color: #f5f5f5;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.mobile-option:hover {
  background-color: #ebf5fb;
  color: #3498db;
  transform: translateY(-2px);
}

.mobile-option.active {
  background-color: #3498db;
  color: white;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.mobile-date-filter {
  width: 100%;
}

.mobile-filter-actions {
  display: flex;
  gap: 10px;
  padding: 15px;
}

.reset-filters-btn, .apply-filters-btn {
  flex: 1;
  padding: 12px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.reset-filters-btn {
  background-color: #f5f5f5;
  color: #666;
  border: 1px solid #e0e0e0;
}

.reset-filters-btn:hover:not(:disabled) {
  background-color: #eee;
  color: #333;
}

.reset-filters-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.apply-filters-btn {
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  color: white;
  border: none;
  box-shadow: 0 2px 5px rgba(41, 128, 185, 0.2);
}

.apply-filters-btn:hover {
  background: linear-gradient(135deg, #2980b9 0%, #1f6dad 100%);
  box-shadow: 0 4px 8px rgba(41, 128, 185, 0.3);
  transform: translateY(-2px);
}

.active-filters-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 15px;
  padding: 5px 0;
}

.filter-tag {
  display: flex;
  align-items: center;
  gap: 5px;
  background-color: #f1f5f9;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.85rem;
  color: #333;
  border: 1px solid #e1e8ed;
}

.remove-filter {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.remove-filter:hover {
  color: #e74c3c;
}

.close-icon {
  font-size: 0.8rem;
}

.clear-all-filters {
  background: none;
  border: 1px solid #e1e8ed;
  color: #666;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 5px;
}

.clear-all-filters:hover {
  background-color: #fef7f7;
  color: #e74c3c;
  border-color: #fdeaea;
}

.main-nav {
  width: 100%;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  margin-bottom: 20px;
  position: relative;
  z-index: 20;
  transition: box-shadow 0.3s ease;
}

.main-nav:hover {
  box-shadow: 0 4px 15px rgba(0,0,0,0.07);
}

.nav-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
}

.nav-left {
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.2s ease;
  text-decoration: none;
  color: inherit;
}

.logo:hover {
  transform: scale(1.02);
}

.logo-icon {
  font-size: 1.5rem;
  color: #3498db;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: #2c3e50;
  letter-spacing: -0.3px;
}

.nav-center {
  display: flex;
  gap: 25px;
}

.nav-link {
  color: #555;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  padding: 5px 0;
  letter-spacing: 0.2px;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background-color: #3498db;
  transition: width 0.3s ease;
}

.nav-link:hover {
  color: #3498db;
}

.nav-link:hover::after {
  width: 100%;
}

.nav-right {
  display: flex;
  align-items: center;
}

.login-btn {
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 5px rgba(41, 128, 185, 0.2);
  letter-spacing: 0.3px;
  position: relative;
  overflow: hidden;
}

.login-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  transition: all 0.6s ease;
}

.login-btn:hover {
  background: linear-gradient(135deg, #2980b9 0%, #1f6dad 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(41, 128, 185, 0.3);
}

.login-btn:hover::before {
  left: 100%;
}

.login-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 3px rgba(41, 128, 185, 0.2);
}

.mobile-menu-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #555;
  transition: all 0.3s ease;
  padding: 10px;
  position: relative;
  z-index: 100;
}

.mobile-menu-btn:hover {
  color: #3498db;
  transform: rotate(90deg);
}

.mobile-nav-menu {
  background-color: white;
  border-top: 1px solid #f0f0f0;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 10px 15px rgba(0,0,0,0.05);
  position: relative;
  z-index: 50;
}

.mobile-nav-menu.open {
  max-height: 500px;
  display: block;
  border-radius: 0 0 8px 8px;
}

.mobile-nav-link {
  display: block;
  padding: 14px 20px;
  color: #555;
  text-decoration: none;
  font-size: 0.95rem;
  border-bottom: 1px solid #f5f5f5;
  transition: all 0.3s ease;
  font-weight: 400;
  letter-spacing: 0.1px;
  position: relative;
}

.mobile-nav-link .menu-icon {
  margin-right: 8px;
  vertical-align: middle;
}

.mobile-nav-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background-color: #3498db;
  transform: scaleY(0);
  transition: transform 0.3s ease;
}

.mobile-nav-link.login-link {
  background-color: #f8fcff;
  color: #3498db;
  font-weight: 500;
  border-top: 1px solid #e8f4fd;
  margin-top: 5px;
}

.mobile-nav-link.login-link:hover {
  background-color: #ebf5fb;
  color: #2980b9;
  padding-left: 25px;
}

.mobile-nav-link.login-link::before {
  background-color: #3498db;
}

.mobile-nav-link:last-child {
  border-bottom: none;
}

.mobile-nav-link:not(.login-link):hover {
  background-color: #f8fcff;
  color: #3498db;
  padding-left: 25px;
}

.mobile-nav-link:hover::before {
  transform: scaleY(1);
}

.logout-link, .logout-item {
  background-color: #fef7f7 !important;
  color: #e74c3c !important;
}

.logout-link:hover, .logout-item:hover {
  background-color: #fdeaea !important;
  color: #c0392b !important;
}

.logout-link::before, .logout-item::before {
  background-color: #e74c3c !important;
}

.date-picker {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  color: #333;
  background-color: white;
  flex: 1;
}

.date-picker:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.clear-date-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #666;
}

.clear-date-btn:hover:not(:disabled) {
  background-color: #f8f9fa;
  border-color: #ccc;
  color: #333;
}

.clear-date-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.user-profile {
  position: relative;
  cursor: pointer;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.user-profile:hover .user-avatar {
  border-color: #3498db;
  transform: scale(1.05);
}

.user-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 200px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 10px 0;
  margin-top: 5px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
}

.user-menu .menu-icon {
  font-size: 0.9rem;
}

.user-menu.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-info {
  padding: 10px 15px;
  border-bottom: 1px solid #f0f0f0;
}

.user-name {
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 3px;
}

.user-email {
  font-size: 0.85rem;
  color: #777;
}

.menu-divider {
  height: 1px;
  background-color: #f0f0f0;
  margin: 5px 0;
}

.menu-item {
  padding: 10px 15px;
  color: #555;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.menu-item:hover {
  background-color: #f8fcff;
  color: #3498db;
  padding-left: 20px;
}

.mobile-user-section {
  padding: 10px 0;
}

.mobile-user-info {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid #f5f5f5;
}

.mobile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 10px;
}

.mobile-user-details {
  flex: 1;
}

.mobile-user-name {
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 2px;
}

.mobile-user-email {
  font-size: 0.8rem;
  color: #777;
}

.nav-link.active {
  color: #3498db;
}

.nav-link.active::after {
  width: 100%;
}

.mobile-nav-link.active {
  background-color: #f8fcff;
  color: #3498db;
  padding-left: 25px;
}

.mobile-nav-link.active::before {
  transform: scaleY(1);
}

@media (max-width: 768px) {
  .mobile-only {
    display: block !important;
  }

  .desktop-only {
    display: none !important;
  }

  .date-filter {
    min-width: auto;
  }

  .logo-text {
    font-size: 1rem;
  }

  .login-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
  }

}

@media (min-width: 769px) {
  .desktop-filter-btn .filter-text {
    display: inline;
  }
}
</style>
